package entity;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;


public class HibernateUtil {
	private static final SessionFactory sessionFactory;
	static {
		try {
			AnnotationConfiguration config = new AnnotationConfiguration();

			config.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
			config.setProperty("hibernate.connection.driver_class", "net.sourceforge.jtds.jdbc.Driver");
			config.setProperty("hibernate.connection.url", "jdbc:jtds:sqlserver://127.0.0.1/hibernate");
			config.setProperty("hibernate.connection.username", "hibernate");
			config.setProperty("hibernate.connection.password", "hibernate");
			config.setProperty("hibernate.connection.pool_size", "2");
			config.setProperty("hibernate.connection.autocommit", "true");

			config.setProperty("hibernate.cache.use_query_cache", "true");
			config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");

			// #hibernate.proxool.pool_alias","pool1");
			// #hibernate.format_sql","true");
			config.setProperty("hibernate.show_sql", "true");

			config.setProperty("hibernate.hbm2ddl.auto", "create-drop");
			// #hibernate.hbm2ddl.auto","create");
			// #hibernate.hbm2ddl.auto","update");
			// #hibernate.hbm2ddl.auto","validate");

			config.setProperty("hibernate.max_fetch_depth", "1");
			config.setProperty("hibernate.jdbc.use_streams_for_binary", "true");
			config.setProperty("hibernate.jdbc.batch_size", "20");

			config.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
			config.setProperty("hibernate.current_session_context_class", "thread");
//			
//			config.addAnnotatedClass(CondicionCompraEntity.class);
//			config.addAnnotatedClass(DomicilioEntity.class);
//			config.addAnnotatedClass(ClienteEntity.class);
			
			sessionFactory = config.buildSessionFactory();
			
		} catch (Throwable ex) {
			System.err.println("Initial SessionFactory creation failed." + ex);
			throw new ExceptionInInitializerError(ex);
		}
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}
}
